﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TDNA
{
   public class BasicCreep : GameObj
    {
        public int HP { get; set; }
        public float Speed { get; set; }
        internal Stack<tdVector2> Route { get; set; }
        public int Delay{ get; private set; }

        public BasicCreep(tdVector2 p, int d)
        {
            Pos = p;
            Delay = d;
            HP = 100;
            Route = new Stack<tdVector2>();
        }

       public BasicCreep(tdVector2 p)
           : this(p,0)
       {
       }

       //Move Bitch!
        public override void Update(ulong gameTime)
        {
            if (Delay > 0) {
                Delay -= (int) gameTime; 
                return;
            }
            
                if (Route.Count > 0)
                {
                    if (!tdVector2.Equals(Pos, Route.Peek())) Pos += tdVector2.Normalize(Route.Peek() - Pos) * (Speed * gameTime / 1000);
                    if (tdVector2.Dist(Route.Peek(), Pos) < Speed * gameTime / 500)
                    {
                        Pos = Route.Pop();                     
                    }
                }            
        }

        public void SetRoute(Stack<tdVector2> r)
        {
            if (r == null) return;
            Route = r;
        }
    }
}
